{include file='public/header' /}
    <style type="text/css">
        .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
        .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
        .header button{float: right;margin-top: -5px;}
    </style>
</head>
<body style="padding: 10px;">
<div class="header">
    <span>租户列表</span>
<!--    <button class="layui-btn layui-btn-sm" onclick="editor()">添加</button>-->
    <div></div>

</div>
<div class="layui-form" lay-filter="formtest" action="">
    <div class="layui-form-item" style="padding-top: 15px">
        <div class="layui-inline">
            <div class="layui-input-inline layui-show-xs-block">
                <input type="text" name="tenant_phone" placeholder="手机号" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline layui-show-xs-block">
                <input type="text" name="tenant_name" placeholder="请输入租户姓名" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline layui-show-xs-block">
                <button class="layui-btn" id="select"  lay-submit lay-filter="select"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </div>
    </div>
</div>
<table id="lists" lay-filter="lists"></table>


<script type="text/javascript">
    layui.use(['layer','form','table'],function(){
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        form.on('switch', function(data){
            // console.log(data.elem.id); //得到checkbox原始DOM对象
            // console.log(data.elem.checked); //开关是否开启，true或者false
            // console.log(data.value); //开关value值，也可以通过data.elem.value得到
            // console.log(data.othis); //得到美化后的DOM对象
            layer.msg('正在提交请稍候。。。', {icon: 16,time: 100000,shade : [0.5 , '#000' , true]});
            $.post('__PUBLIC__/admin/tenant/status',{'id':data.elem.id,'tenant_status':data.elem.checked},function (res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                    if(data.elem.checked == false){
                        data.elem.checked = true
                    }else {
                        data.elem.checked = false
                    }
                    form.render();
                }else {
                    layer.msg(res.msg,{icon:1,time:1100});
                    //location.reload();
                }
            },'json');
        });
        // form.val("formtest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
        //     "con_contract_id": '' // "name": "value"
        //     ,"use_id": ''
        //     ,"own_id": ''
        // });
        form.on('submit(select)', function(data){
            //var msg = document.getElementById('msg').value;
            tenant_phone=data.field.tenant_phone;
            tenant_name=data.field.tenant_name;
            getdata = '';
            if (tenant_phone && typeof(tenant_phone)!=undefined && tenant_phone!=0) {
                getdata += '&tenant_phone=' + tenant_phone;
            }
            if (tenant_name && typeof(tenant_name)!=undefined && tenant_name!=0) {
                getdata += '&tenant_name=' + tenant_name;
            }
            var table = layui.table;
            table.render({
                elem: '#lists'
                ,height: 'full-144'
                ,url: '__PUBLIC__/admin/tenant/order_check?'+getdata //数据接口
                ,page: true //开启分页
                // ,size: 'sm'
                ,cellMinWidth:60
                // ,even: true
                ,cols: [[ //表头
                    {field: 'o_id', title: '电费订单', }
                    ,{field: 'h_id', title: '房屋', minWidth:120}
                    ,{field: 'r_id', title: '房间号', minWidth:120}
                    ,{field: 't_id', title: '租户', minWidth:100}
                    ,{field: 'public_usage', title: '公共电量',minWidth:100}
                    ,{field: 'checkin_num', title: '入住人数', minWidth:120}
                    ,{field: 'room_usage', title: '房间电量', minWidth:200, }
                    ,{field: 'total', title: '金额', minWidth: 120, }
                    ,{field: 'status', title: '扣费状态', minWidth: 120, }
                    ,{field: 'create_time', title: '创建时间', minWidth: 120, }
                    ,{field: 'operation', title: '操作',minWidth: 120}
                ]]
            });
            return false;
        });
        form.on('submit(editor)', function(data){
            layer.open({
                type: 2,
                title: data.elem.id>0?'编辑资料':'添加人员',
                shade: 0.3,
                area: ['620px', '480px'],
                content: '__PUBLIC__/admin/tenant/add?id='+data.elem.id

            });
        });
        form.on('submit(del)', function(data){
            var item_table = table.cache['lists'];
            console.log(item_table);
            console.log(data);
            for (var index in item_table) {
                if(item_table[index].id == data.elem.id){
                    var name = item_table[index].truename;
                }
            }
            layer.confirm('确认要删除'+name+'吗？',{
                btn: ['是的','取消'] //按钮
            }, function(){
                layer.msg('正在提交删除。。。', {icon: 16,time: 10000,shade : [0.5 , '#000' , true]});
                $.post('__PUBLIC__/admin/tenant/del',{'id':data.elem.id},function (res){
                        if(res.code>0){
                        layer.alert(res.msg,{icon:2});
                    }else {
                        layer.msg(res.msg,{icon:1,time:1100});
                        location.reload();
                    }
                },'json');
            });
        });
        $(document).ready(function(){
            $("#select").click();
        });
    });
</script>
</body>
</html>
